using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace DAO
{
    public class TheLoaiSach : Interface
    {
        public string LayMaTheLoai(string tenTheLoai)
        {
            string s = Application.StartupPath;
            Provider p = new Provider("Server=.\\SQLEXPRESS;AttachDbFilename=" + s + "\\QLTV.mdf; Trusted_Connection=Yes;Integrated security=true;User Instance=true");
            DataTable dt = p.ExecuteQuery("SELECT * FROM TheLoaiSach");
            if(dt == null)
            {
                Provider p1 = new Provider("Server=.\\;AttachDbFilename=" + s + "\\QLTV.mdf; Trusted_Connection=Yes;Integrated security=true;User Instance=true");
                dt = p1.ExecuteQuery("SELECT * FROM TheLoaiSach");
            }
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (tenTheLoai.Trim() == dt.Rows[i]["TenTheLoai"].ToString().Trim())
                    return dt.Rows[i]["MaTheLoai"].ToString();
            }
            return "";
        }
    }
}
